package com.lins.framework.mvpframe.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.lins.framework.common.base.BaseActivity;
import com.lins.framework.common.base.MyApplication;
import com.lins.framework.mvpframe.util.TUtil;
import com.lins.framework.utils.tip.DialogUtil;
import com.lins.framework.utils.tip.LoadingDialogUtil;

/**
 * Created by Admin on 2017/3/13.
 */

public class BaseFrameActivity<P extends BasePresenter, M extends BaseModel> extends BaseActivity implements BaseView {
    public P mPresenter;
    public M mModel;
    protected Context context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = TUtil.getT(this, 0);
        mModel = TUtil.getT(this, 1);
        if (this instanceof BaseView) {
            mPresenter.attachVM(this, mModel);
        }
    }

    @Override
    protected void onDestroy() {
        if (mPresenter != null)
            mPresenter.detachVM();
        super.onDestroy();
    }

    @Override
    public void onRequestStart(String msg) {
        LoadingDialogUtil.showLoading(context, msg);
    }

    @Override
    public void onRequestError(String msg) {
        LoadingDialogUtil.hideLoading();
        DialogUtil.showTipDialog(getSupportFragmentManager(), msg, MyApplication.getInstance().getActivityManager().currentActivity().toString());
    }

    @Override
    public void onRequestEnd() {
        LoadingDialogUtil.hideLoading();
    }

    @Override
    public void onInternetError() {

    }
}
